﻿Imports Microsoft.VisualBasic
Imports System.Data

<System.ComponentModel.DataObjectAttribute(True)> _
Public Class BLL_QueryEnlistment

    Public Sub New()
        ' 
        ' TODO: 在此加入建構函式的程式碼 
        ' 
    End Sub

    'SELECT 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.[Select])> _
    Public Function BLL_Select(ByVal UOrganizationID As String, ByVal annual As String) As DataTable

        Dim sql As New MyOrganizationDataFilter(True)
        Dim dat As New clsData

        sql.AppendFormat("SELECT A.*,B.OrganizationName ")
        sql.AppendFormat("FROM EnlistHeader A  ")
        sql.AppendFormat("inner join OrganizationView B on A.UOrganizationID = B.UOrganizationID ")
        sql.AppendFormat("where 1=1 ")

        If UOrganizationID <> "" Then
            sql.AppendFormat("and A.UOrganizationID='{0}' ", UOrganizationID)
        End If

        If annual <> "" Then
            sql.AppendFormat("and year(A.StartDate) = {0} ", annual)
        End If

        'MyObj.WriteLog(sql.ToString())

        sql.AppendFormat("ORDER BY A.EnlistID ")

        Return dat.GetData(sql)

    End Function

    'Delete 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete)> _
    Public Sub BLL_Delete(ByVal original_EnlistID As Integer)

        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.Length = 0
            sql.AppendFormat("DELETE EnlistHeader WHERE EnlistID={0};", original_EnlistID)
            sql.AppendFormat("DELETE EnlistTrainingCourse WHERE EnlistID={0};", original_EnlistID)
            dat.AccData(sql)

            scope.Complete()

        End Using

    End Sub

End Class
